package IO.Buffered;

import java.io.*;

/**
 * 数据流
 * 1.写出后读取
 * 2.读取的顺序与写出保持一致
 */
public class DataTest {
    public static void main(String[] args) throws IOException {
        //写出
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(baos) );
        //操作数据类型 + 数据
        dos.writeUTF("啊啊");
        dos.writeChar('a');
        dos.writeBoolean(true);
        dos.writeInt(18);
        dos.flush();

        byte[] data = baos.toByteArray();
        //读取
        DataInputStream dis = new DataInputStream(new BufferedInputStream(new ByteArrayInputStream(data)) );
        System.out.println(dis.readUTF());

    }
}
